<?php
/**
 * Created by PhpStorm.
 * User: yunpeng
 * Date: 2019/1/3
 * Time: 13:44
 */

namespace App\Admin\Controllers;

//use App\Models\Platform;
use App\Models\Plat;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Show;

class PlatformController  extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header('配置列表');
            $content->body($this->grid());
        });
    }



    /**
     * Index interface.
     *
     * @return Content
     */
    public function show(Content $content)
    {
        return $content->header('平台介绍')
            ->description('详情')
            ->body(Admin::show(Plat::findorfail(1), function (Show $show) {
                $show->id('ID');
                $show->word('文字');
                $show->img('图片')->as(function ($img) {
                    foreach($img as $k=>$v){
                        return $v;
                    }
                })->image();
                $show->created_at();
                $show->updated_at();
            }));
    }





    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {
            $content->header('平台介绍编辑');
            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {
            $content->header('创建平台介绍');
            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Plat::class, function (Grid $grid) {
            $grid->item('属性');
            $grid->word('文字');
            $grid->img('图片')->image(env('APP_URL')."/storage",100,100);
            $grid->disableCreateButton();
            $grid->disableExport();
            //禁用批量删除按钮
            $grid->tools(function ($tools) {
                $tools->batch(function ($batch) {
                    $batch->disableDelete();
                });
            });
            //隐藏操作
            $grid->actions(function ($actions) {
                $actions->disableDelete();
                $actions->disableView();
            });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        // 创建一个表单
        return Admin::form(Plat::class, function (Form $form) {
            $form->text('item', '属性')->rules('required');
            $form->text('word', '文字')->rules('required');
            $form->multipleImage('img', '图片')->removable()->rules('image');
        });
    }
}
